﻿using DevExpress.XtraBars;
using DevExpress.XtraGrid.Views.Base;
using NAGFwk.BL;
using NAGFwk.UI;
using SilkeyERP.BL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SilkeyERP.UI.Entities.TaxFigure
{
    public partial class ContentView :  BaseContentDetail
    {
        private readonly IBaseController<Model.TaxFigure> _controller = new TaxFigureController();

        public override string ModuleName { get { return "TaxFigure"; } }

        public ContentView()
        {
            InitializeComponent();
        }

        public override void ShowModule(bool firstShow)
        {
            base.ShowModule(true);
            MapItLoad(_controller);
            taxBindingSource.DataSource = new TaxController().GetAll();
        }

        private void bbiDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            MapItDelete(_controller);
        }

        private void gvBaseContentDetail_RowUpdated(object sender, RowObjectEventArgs e)
        {
            MapItUpdate(e, _controller);
        }

        private void bbiRefresh_ItemClick(object sender, ItemClickEventArgs e)
        {
            MapItRefresh(_controller);
        }

        private void gvBaseContentDetail_ValidateRow(object sender, ValidateRowEventArgs e)
        {
            var myObj = (Model.TaxFigure)e.Row;

            if (((Model.TaxFigure)e.Row).TaxID == int.MinValue)
            {
                e.ErrorText = "Impuesto es Requerido.";
                e.Valid = false;
            }

            if (string.IsNullOrEmpty(myObj.Description))
            {
                e.ErrorText = "Descripcion es Requerido.";
                e.Valid = false;
            }
        }
    }
}
